package cc.marcio.systems.seven.dao;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.criterion.Expression;

import cc.marcio.systems.seven.model.Contact;


@SuppressWarnings("serial")
public class ContactDao extends BaseDaoImpl<Contact> implements BaseDao<Contact> {

	protected ContactDao(Session session) {
		super(session);
	}
	
	@SuppressWarnings("unchecked")
	public List<Contact> listPerUserAndDom(Contact contact) {
		Criteria criteria = this.session.createCriteria(Contact.class);
		criteria.add(Expression.eq("id.user", contact.getId().getUser()))
		.add(Expression.eq("id.contactdom", contact.getId().getContactdom()));
		return criteria.list();
	}

	@Override
	protected void addPropertiedToCriteria(Criteria criteria, Contact example) {
		if( example.getId() != null ) {
			if( example.getId().getContactdom() != null ) {
				criteria.add(Expression.eq("id.contactdom", example.getId().getContactdom()));
			}
			if( example.getId().getUser() != null ) {
				criteria.add(Expression.eq("id.user", example.getId().getUser()));
			}
		}
	}
}